module SuicideTranslators where

---------------- Non brainfuck-like langs -------------------
-- TODO: Suicide to MidLevel
-- | Suicide to Mid-level C-like lang tranlators
suicideToMidLevel :: [Char] -> [[Char]]
suicideToMidLevel txt = map(suicideToMidLevelStrings) $ lines txt

-- | Translates a suicide operation into a Mid-level C-like instruction
suicideToMidLevelStrings :: [Char] -> [Char]
suicideToMidLevelStrings a
        | not (null(isnum)) = show $ fst (isnum !! 0)
        -- Variables
        | var   = drop 2 (fst w) ++ " = " ++ suicideToMidLevelStrings (drop 1 (snd w))
        -- Relational operators
        | equ   = drop 2 (fst w) ++ " == " ++ suicideToMidLevelStrings (drop 2 (snd w))
        | neq   = drop 2 (fst w) ++ " != " ++ suicideToMidLevelStrings (drop 2 (snd w))
        | smt   = drop 2 (fst cm1) ++ " < " ++ suicideToMidLevelStrings (drop 2 (snd cm1))
        | sme   = drop 2 (fst cm1) ++ " <= " ++ suicideToMidLevelStrings (drop 2 (snd cm1))
        | bgt   = drop 2 (fst cm2) ++ " > " ++ suicideToMidLevelStrings (drop 2 (snd cm2))
        | bge   = drop 2 (fst cm2) ++ " >= " ++ suicideToMidLevelStrings (drop 2 (snd cm2))
        -- Loops 
        
        -- TODO: Functions (WTF?)
        | otherwise = ""
        
        where isnum = reads a :: [(Int,String)]
              w = break (==':') a
              var = length (snd w) > 0  -- Bloody Nora!
                         && (!!) (fst w) 1 == 'v'
                         && null (snd (break (=='>') (fst w)))
                         && null (snd (break (=='<') (fst w)))
                         && not((!!) (snd w) 1 == ':') 
                         && not((!!) (snd w) 1 == '.')
                         
              cm1 = break (=='<') a
              cm2 = break (=='>') a
              equ = length (snd w) > 0 && (!!) (snd w) 1 == ':'
              neq = length (snd w) > 0 && (!!) (snd w) 1 == '.'
              smt = length (snd cm1) > 0 && (!!) (snd cm1) 1 == '.'
              sme = length (snd cm1) > 0 && (!!) (snd cm1) 1 == ':'
              bgt = length (snd cm2) > 0 && (!!) (snd cm2) 1 == '.'
              bge = length (snd cm2) > 0 && (!!) (snd cm2) 1 == ':'
              